<template>
    <div class="zygl-edit">
<el-form ref="form" :model="form" label-width="80px" :rules="rules">
  <el-form-item label="用户名" prop="username">
    <el-input v-model="form.username"></el-input>
  </el-form-item>
  <el-form-item label="权限">
    <el-checkbox-group v-model="form.privileges">
    <el-checkbox :label="1">系管理</el-checkbox>
    <el-checkbox :label="2">专业管理</el-checkbox>
    <el-checkbox :label="4">班级管理</el-checkbox>
    <el-checkbox :label="8">学生管理</el-checkbox>
    <el-checkbox :label="16">教师管理</el-checkbox>
    <el-checkbox :label="32">课程管理</el-checkbox>
    <el-checkbox :label="64">选课修改</el-checkbox>
    <el-checkbox :label="128">管理员管理</el-checkbox>
  </el-checkbox-group>
  </el-form-item>
  
  <el-form-item label="密码" prop="password">
    <el-input v-model="form.password"></el-input>
  </el-form-item>
</el-form>
    </div>
</template>
<script>
import {glyglDetail} from '@/api/glygl'
export default{
    //获取父传子
    props:["id"],
    data(){
        return{
            form:{
                username:"",
                id:-1,
                password:"",
                privileges:[]
            },
            rules:{
               username: [
                {required: true, message: '请输入系名称', trigger: 'blur'}
            ],
            },
        }
    },
    methods:{
        onSubmit(cb){
            this.$refs["form"].validate(flag=>{
                if(flag){
                    this.form["privilege"]=this.form.privileges.reduce((a,b)=>a+b);
                    console.log("参数",this.form);
                    // glyglEdit(this.form).then(res =>{
                    //     cb(res)
                    // })
                }
            })
        },
        getDetail(){  
               glyglDetail(this.id).then(res=>{
                console.log(res);
                if(res.code===0){
                    let group = []
                            for (let bit = 0; bit < 8; bit++) {
                                // 0100 0000
                                // 0010 0000
                                if (((1 << bit) & res.data.privilege) === 1 << bit) {
                                    group.push((1 << bit));
                                }
                            }
                            console.log(group);
                            res.data.privileges= group
                    this.form= res.data
                }        
            })         
        },
    //     getList(){
    //     departmentAll().then(res=>{
    //       console.log(res);
    //       if(res.code===0){
    //         this.options=res.data
    //       }
    //     })
    //   }
    },
    mounted(){
        this.getDetail() 
        // this.getList()    
    }
}
</script>